import java.util.EmptyStackException;
import java.util.Stack;

public class StackDemo {
    static void showPush(Stack<Integer> st, int a) {

        st.push(new Integer(a));
        System.out.println("push(" + a + ")");
        System.out.println("stack: " + st);
    }


    static void showPop(Stack<Integer> st) {
        System.out.print("pop -> ");
        Integer a = (Integer) st.pop();
        System.out.println(a);
        System.out.println("stack: " + st);
    }


    public static void test(int x) {
        Stack<Integer> s1 = new Stack<Integer>();
        Stack<Integer> s2 = new Stack<Integer>();
        s1.push(x);
        s2.push(x);
        int p1 = s1.peek();
        int p2 = s2.peek();
        System.out.println(p1 == p2);
        System.out.println(s1.peek() == s2.peek());

    }

    public static void main(String args[]) {
        Stack<Integer> st = new Stack<Integer>();
        System.out.println("stack: " + st);
        showPush(st, 42);
        showPush(st, 66);
        showPush(st, 99);

        try {
            showPop(st);
            showPop(st);
            showPop(st);
            showPop(st);
        } catch (EmptyStackException e) {
            System.out.println("empty stack");
        }
        test(1);
        test(128);
    }

}
